package cn.huhst.cas.weisiqian.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import cn.huhst.cas.weisiqian.dbhelp.DBHelper;
import cn.huhst.cas.weisiqian.pojo.Picture;

public class PhotoWallDao {

	private Logger logger = Logger.getLogger(PhotoWallDao.class);

	public boolean addPicture(Picture picture) {
		boolean result = false;
		logger.info("保存" + picture.getPicturename() + " 照片信息");
		Connection connection = DBHelper.getConnection();
		PreparedStatement pstmt = null;
		String sql = "INSERT INTO photowall(picturename,picturedesc,competitionname) value(?,?,?)";
		try {
			pstmt = connection.prepareStatement(sql);
			pstmt.setString(1, picture.getPicturename());
			pstmt.setString(2, picture.getPicturedesc());
			pstmt.setString(3, picture.getCompetitionname());
			int count = pstmt.executeUpdate();
			if (count > 0) {
				result = true;
				logger.error("保存照片：" + picture.getPicturename() + " 的照片信息成功");
			} else {
				logger.error("保存照片：" + picture.getPicturename() + " 的照片信息失败");
			}
		} catch (SQLException e) {
			logger.error("保存照片：" + picture.getPicturename() + " 的照片信息失败", e);
		} finally {
			DBHelper.closeDBHelp(connection, pstmt, null);
			logger.info("关闭数据库连接");
		}
		return result;
	}
}
